package com.yjt.fresh.adpater;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.donkingliang.groupedadapter.adapter.GroupedRecyclerViewAdapter;
import com.donkingliang.groupedadapter.holder.BaseViewHolder;
import com.yjt.fresh.R;
import com.yjt.fresh.bean.BeanHistoryHome;

import java.util.List;

public class AdpFrgHistoryHome extends GroupedRecyclerViewAdapter {

    private final List<BeanHistoryHome.VideoListBean> mVideoList;

    public AdpFrgHistoryHome(Context context, List<BeanHistoryHome.VideoListBean> videoList) {
        super(context);
        mVideoList = videoList;
    }

    @Override
    public int getGroupCount() {
        return mVideoList == null ? 0 : mVideoList.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        List<BeanHistoryHome.VideoListBean.ListBean> list = mVideoList.get(groupPosition).getList();
        return list == null ? 0 : list.size();
    }

    @Override
    public boolean hasHeader(int groupPosition) {
        return true;
    }

    @Override
    public boolean hasFooter(int groupPosition) {
        return false;
    }

    @Override
    public int getHeaderLayout(int viewType) {
        return R.layout.app_recycle_item_frg_history_home_head;
    }

    @Override
    public int getFooterLayout(int viewType) {
        return 0;
    }

    @Override
    public int getChildLayout(int viewType) {
        return R.layout.app_recycle_item_frg_history_home_content;
    }

    @Override
    public void onBindHeaderViewHolder(BaseViewHolder holder, int groupPosition) {
        ImageView imageView = holder.get(R.id.ivAppRecycleItemFrgHistoryHomeHead);
        Glide.with(imageView.getContext()).load(mVideoList.get(groupPosition).getIMG()).into(imageView);
    }

    @Override
    public void onBindFooterViewHolder(BaseViewHolder holder, int groupPosition) {

    }

    @Override
    public void onBindChildViewHolder(BaseViewHolder holder, int groupPosition, int childPosition) {
        ImageView imageView = holder.get(R.id.ivAppRecycleItemFrgHistoryHomeContent);
        Glide.with(imageView.getContext()).load(mVideoList.get(groupPosition).getList().get(childPosition).getCOVERIMAGE()).into(imageView);
        holder.setText(R.id.tvAppRecycleItemFrgHistoryHomeContentTitle, mVideoList.get(groupPosition).getList().get(childPosition).getTITLE());
    }
}
